-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Replace π-related bound constants with next_up/next_down #16823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace π-related bound constants with next_up/next_down #16823
Conversation
- Replaced 8 hardcoded π constants with std library next_up/next_down methods - All f32 constants remain identical (perfect precision match) - f64 π constants improved by ~4.4e-16 (better mathematical precision) - Removed clippy::approx_constant allows (no longer needed) - Updated comments to explain bounds purpose and method - Removed obsolete TODO comment about next_up/next_down stabilization Closes apache#16712"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rthummaluru -- once this this PR passes CI tests it looks good to me
Current MSRV is 1.85.1. We need to wait until MSRV=1.86. |
MSRV was updated by @adriangb in I merged up from main and kicked off tests again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I looked at just a white space commit and thought that was it buts is more involved than that. I’ll let @alamb approve
I think this one is good to go -- it has been waiting until we could use the new rust features |
Thanks everyone |
Which issue does this PR close?
Closes #16712.
Rationale for this change
Rust 1.86 stabilized f64::next_up() and f32::next_up() methods, along with their next_down() counterparts. These methods provide IEEE 754 compliant ways to get the next representable floating-point value, which is more precise and maintainable than manually calculated hardcoded constants.
The existing hardcoded π-related constants were close approximations, but using the standard library methods ensures mathematical correctness and improves code clarity.
What changes are included in this PR?
Replaced 8 hardcoded π-related floating-point constants with next_up()/next_down() calls
Removed #[allow(clippy::approx_constant)] attributes (no longer needed)
Updated comments to explain the purpose (bounds) and method (next_up/next_down)
Removed obsolete TODO comment about next_up/next_down stabilization
Constants updated:
PI_UPPER_F32/F64 → std::f32/f64::consts::PI.next_up()
NEGATIVE_PI_LOWER_F32/F64 → (-std::f32/f64::consts::PI).next_down()
FRAC_PI_2_UPPER_F32/F64 → std::f32/f64::consts::FRAC_PI_2.next_up()
NEGATIVE_FRAC_PI_2_LOWER_F32/F64 → (-std::f32/f64::consts::FRAC_PI_2).next_down()
Value Analysis:
All f32 constants remain identical (perfect precision match)
f64 π constants show minor precision improvements (~4.4e-16)
f64 π/2 constants remain identical
Are these changes tested?
Yes, these changes are tested by existing tests. The constants are used in mathematical functions throughout DataFusion, and all existing tests continue to pass, confirming compatibility.